<?php
  /**
   * iJGroups
   *
   * The iJGroups class manages user groups
   *
   * @copyright Copyright (c) 2011, iJBlocks Progect
   */
   class iJGroups implements iJSingleton {
     /**
      * show error message in browser
      * @var boolean
      * @access private
      */
     private $groups = null;
    
     /**
      * show error message in browser
      * @var boolean
      * @access private
      */
     private $allGroupIndex = null;
     
     /**
      *
      * Class Constructuctor
      * 
      * @access public
      */
     public function __construct() {
      
     }
     
     /**
      * returns db index of group with key word all
      * @return int group index
      * @access public
      */
     public function getAllGroupIndex() {
       return $this->allGroupIndex;
     }
     
     /**
      * retruns mixed array of usr groups
      * @return mixed array of user groups
      * @access public
      */
     public function getGroups() {
      if($this->groups == null) {
        $iJDataBase  =  iJFactory::singleton('iJDataBase');
        $QGroups    =  $iJDataBase->query('SELECT 
                                            id, 
                                            name 
                                          FROM :table_groups
                                          ');
        $QGroups->bindTable(':table_groups', TABLE_GROUPS);
        $QGroups->execute();
        $groups = array();
        while($QGroups->next()) {
          $group['id']  = $QGroups->value('id');
          $group['key'] = $QGroups->value('name');
          
          if($group['key'] == 'all') {
            $this->allGroupIndex = $group['id'];
          }
          $groups[] = $group;
        }
        $this->groups = $groups;
        return $groups;
      } else {
        return $this->groups;
      }
     }
     
     
     
   }
    
?>